const images = require('images');

function render(viewport,element){
    if (element.sytle) {
        var img = images(element.sytle.width,element.sytle.height);

        if (element.sytle['background-color']) {
            let color = element.sytle['background-color'] || "rgb(0,0,0)";
            color.match(/rgb\((\d+),(\d+),(\d+)\)/);
            img.fill(Number(RegExp.$1),Number(RegExp.$2),Number(RegExp.$3),1);
            viewport.draw(img,element.sytle.left||0,element.sytle.top||0);
        }

    }
    if (element.children) {
        for (const child of element.children) {
            render(viewport,child);
        }
    }
}

module.exports = render;